﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ANZ_AIM_BLL.Model;
using ANZ_AIM_GUI.Utils;
using ANZ_AIM_BLL;
using ANZ_AIM_FRAMEWORK;
using DevComponents.DotNetBar.Controls;
using System.Text.RegularExpressions;
using log4net;

namespace ANZ_AIM_GUI
{
    public partial class frmSalesMgmt : Form
    {
        //log4net
        private static readonly ILog logger = LogManager.GetLogger(typeof(frmSalesMgmt));

        public Dictionary<string, string> SaleInfo_FieldLabelDict { get; set; }

        DataTable dtDataSaleInfoTemp = new DataTable();
        public SaleInfo saleInfo { get; set; }
        public SaleInfo saleInfoTemp { get; set; }

        public List<SaleChangeRequest> saleChangeRequestList = new List<SaleChangeRequest>();
        public List<SaleChangeTemp> saleChangeTempList = new List<SaleChangeTemp>();
        protected AppParam appParam = AppParam.Instance;

        public frmSalesMgmt()
        {
            InitializeComponent();
            LoadComponent();

            try
            {
                BuildEmploymentOfflineLabel();

                LoadDataSaleInfo();

                //load info change
                

                //load column
                dtDataSaleInfoTemp = new SaleChangeTempBLL().GetSaleChangeTempInfo();
                RefreshEmploymentChangeCount();
            }
            catch (Exception ex) { throw ex; }
        }
        private void LoadComponent()
        {
            this.groupBox3.Visible = appParam.Role.Contains(User.ROLE_EXECUTER);

        }
        public void LoadDataSaleInfo()
        {
            //load employment offline
            SaleInfoBLL saleInfoBll = new SaleInfoBLL();
            DataTable dtData = saleInfoBll.GetSaleInfo();
            dgvData.DataSource = null;
            dgvData.Columns.Clear();
            dgvData.DataSource = dtData;
            dgvData.AutoResizeColumns();

            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(SaleInfo));
            foreach (PropertyDescriptor prop in properties)
            {
                dgvData.Columns[prop.Name].HeaderText = SaleInfo_FieldLabelDict[prop.Name];

                string dataType = prop.PropertyType.Name;

                if (!dataType.ToUpper().Equals("STRING"))
                {
                    dgvData.Columns[prop.Name].DefaultCellStyle.Format = "dd MMM, yyyy";
                }
            }
            dgvData.Columns[0].DefaultCellStyle.Format = "###";
        }

        public void BuildEmploymentOfflineLabel()
        {
            SaleInfo_FieldLabelDict = new Dictionary<string, string>();
            SaleInfo_FieldLabelDict.Add("ID", "ID");// show header when load data from database
            SaleInfo_FieldLabelDict.Add("ProfileID", "Profile ID");
            SaleInfo_FieldLabelDict.Add("SaleCode", "Sale Code");
            SaleInfo_FieldLabelDict.Add("CVCode", "CV Code");

            SaleInfo_FieldLabelDict.Add("EmployeeFullName", "Employee Full Name");
            SaleInfo_FieldLabelDict.Add("EmployeeFullNameE", "Employee Full Name_E");
            SaleInfo_FieldLabelDict.Add("Role", "Role");
            SaleInfo_FieldLabelDict.Add("Level", "Level");
            SaleInfo_FieldLabelDict.Add("Category", "Category");
            SaleInfo_FieldLabelDict.Add("ProductCategory", "Product Category");
            SaleInfo_FieldLabelDict.Add("Product", "Product");
            SaleInfo_FieldLabelDict.Add("TeamName", "Team Name");
            SaleInfo_FieldLabelDict.Add("TeamLeaderCode", "Team Leader Code");
            SaleInfo_FieldLabelDict.Add("Channel", "Channel");
            SaleInfo_FieldLabelDict.Add("JoiningDate", "Joining Date");
            SaleInfo_FieldLabelDict.Add("PromotionTransferDate", "Promotion Transfer Date");
            SaleInfo_FieldLabelDict.Add("Status", "Status");
            SaleInfo_FieldLabelDict.Add("IDCardNumber", "ID Card Number");
            SaleInfo_FieldLabelDict.Add("DateOfBirth", "Date Of Birth");
            SaleInfo_FieldLabelDict.Add("IDIssuedDate", "ID Issued Date");
            SaleInfo_FieldLabelDict.Add("IDIssuedPlace", "ID Issued Place");
            SaleInfo_FieldLabelDict.Add("PermanentAddress", "Permanent Address");
            SaleInfo_FieldLabelDict.Add("MobilePhone", "Mobile Phone");
            SaleInfo_FieldLabelDict.Add("FingerID", "Finger ID");
            SaleInfo_FieldLabelDict.Add("PersonalTaxCode", "Personal Tax Code");
            SaleInfo_FieldLabelDict.Add("ContractType", "Contract Type");
            SaleInfo_FieldLabelDict.Add("ContractTerm", "Contract Term");
            SaleInfo_FieldLabelDict.Add("ContractorName", "Contractor Name");
            SaleInfo_FieldLabelDict.Add("ContractSignDate", "Contract Sign Date");
            SaleInfo_FieldLabelDict.Add("ContractExpiryDate", "Contract Expiry Date");
            SaleInfo_FieldLabelDict.Add("BankAccount", "Bank Account");
            SaleInfo_FieldLabelDict.Add("BankBranchAddress", "Bank Branch Address");
            SaleInfo_FieldLabelDict.Add("BankName", "Bank Name");
            SaleInfo_FieldLabelDict.Add("FillingRefCode", "Filling Ref Code");
            SaleInfo_FieldLabelDict.Add("ProfressiveTarget", "Profressive Target");
            SaleInfo_FieldLabelDict.Add("BatchFileID", "Batch File ID");
        }
        private SaleInfo UnPackObjectData_SaleInfo(DataRow drData)
        {
            saleInfo = new SaleInfo();
            saleInfo.ProfileID = drData["ProfileID"].ToString();
            saleInfo.SaleCode = drData["SaleCode"].ToString();
            saleInfo.CVCode = drData["CVCode"].ToString();
            saleInfo.EmployeeFullName = drData["EmployeeFullName"].ToString();
            saleInfo.EmployeeFullNameE = drData["EmployeeFullNameE"].ToString();
            saleInfo.Role = drData["Role"].ToString();
            saleInfo.Level = drData["Level"].ToString();
            saleInfo.Category = drData["Category"].ToString();
            saleInfo.ProductCategory = drData["ProductCategory"].ToString();
            saleInfo.Product = drData["Product"].ToString();
            saleInfo.TeamName = drData["TeamName"].ToString();
            saleInfo.TeamLeaderCode = drData["TeamLeaderCode"].ToString();
            saleInfo.Channel = drData["Channel"].ToString();
            saleInfo.JoiningDate = Convert.ToDateTime(drData["JoiningDate"] != null ? drData["JoiningDate"] : (DateTime?)null);
            saleInfo.PromotionTransferDate = Convert.ToDateTime(drData["PromotionTransferDate"] != null ? drData["PromotionTransferDate"] : (DateTime?)null);
            saleInfo.Status = drData["Status"].ToString();
            saleInfo.IDCardNumber = drData["IDCardNumber"].ToString();
            saleInfo.DateOfBirth = Convert.ToDateTime(drData["DateOfBirth"] != null ? drData["DateOfBirth"] : (DateTime?)null);
            saleInfo.IDIssuedDate = Convert.ToDateTime(drData["IDIssuedDate"] != null ? drData["IDIssuedDate"] : (DateTime?)null);
            saleInfo.IDIssuedPlace = drData["IDIssuedPlace"].ToString();
            saleInfo.PermanentAddress = drData["PermanentAddress"].ToString();
            saleInfo.MobilePhone = drData["MobilePhone"].ToString();
            saleInfo.FingerID = drData["FingerID"].ToString();
            saleInfo.PersonalTaxCode = drData["PersonalTaxCode"].ToString();
            saleInfo.ContractType = drData["ContractType"].ToString();
            saleInfo.ContractTerm = drData["ContractTerm"].ToString();
            saleInfo.ContractorName = drData["ContractorName"].ToString();
            saleInfo.ContractSignDate = Convert.ToDateTime(drData["ContractSignDate"] != null ? drData["ContractSignDate"] : (DateTime?)null);
            saleInfo.ContractExpiryDate = Convert.ToDateTime(drData["ContractExpiryDate"] != null ? drData["ContractExpiryDate"] : (DateTime?)null);
            saleInfo.BankAccount = drData["BankAccount"].ToString();
            saleInfo.BankBranchAddress = drData["BankBranchAddress"].ToString();
            saleInfo.BankName = drData["BankName"].ToString();
            saleInfo.FillingRefCode = drData["FillingRefCode"].ToString();
            saleInfo.ProfressiveTarget = drData["ProfressiveTarget"].ToString();
            saleInfo.BatchFileID = drData["BatchFileID"].ToString();
            return saleInfo;
        }

        #region Action
        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                string saleCode = txtSaleCode.Text.Trim();
                string fullName = txtFullName.Text.Trim();
                string profileID = txtProfileID.Text.Trim();
                string batchFileID = txtBatchFile.Text.Trim();

                if (string.IsNullOrEmpty(saleCode))
                {
                    saleCode = null;
                }
                if (string.IsNullOrEmpty(fullName))
                {
                    fullName = null;
                }
                if (string.IsNullOrEmpty(profileID))
                {
                    profileID = null;
                }
                if (string.IsNullOrEmpty(batchFileID))
                {
                    batchFileID = null;
                }

                SaleInfoBLL saleInfoBll = new SaleInfoBLL();
                DataTable dtData = saleInfoBll.Search(saleCode, fullName, profileID, batchFileID);

                dgvData.DataSource = null;
                dgvData.Columns.Clear();
                dgvData.DataSource = dtData;
                dgvData.AutoResizeColumns();

                PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(SaleInfo));
                foreach (PropertyDescriptor prop in properties)
                {
                    dgvData.Columns[prop.Name].HeaderText = SaleInfo_FieldLabelDict[prop.Name];
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.InnerException == null ? ex.Message : ex.InnerException.Message, Constant.SYS_ERROR, MessageBoxButtons.OK);
                logger.Error(ex.Message + " - " + ex.StackTrace);
            }
        }
        private void btnUpdateEmployment_Click(object sender, EventArgs e)
        {
            try
            {
                string[] noTeam_Channel = new string[] {
                "TS In-house HN 1", "TS In-house HN 2", "TS In-house HN 3",
                "TS In-house 1", "TS In-house 2", "TS In-house 3",
                "TS In-house 4", "TS Portfolio", "Field Sales HN", "Field Sales HCM"
                };
                if (!ValidateUpdateChange())
                {
                    return;
                }

                if (chbBatchFile.Checked)
                {
                    //save in datatable -> view 
                    DataRow dr = dtDataSaleInfoTemp.NewRow();
                    DataRow[] foundRows = dtDataSaleInfoTemp.Select("BatchFile= '" + txtBatchFileChange.Text + "' AND FieldChange = '" + cbField.Text + "'");
                    if (foundRows.Length > 0)
                    {
                        foundRows[0]["NewValue"] = txtNewValue.Text;
                    }
                    else
                    {
                        dr["BatchFile"] = txtBatchFileChange.Text;
                        dr["FieldChange"] = cbField.Text;
                        dr["OldValue"] = txtOldValue.Text;
                        dr["NewValue"] = txtNewValue.Text;
                        dtDataSaleInfoTemp.Rows.Add(dr);
                    }
                    if (cbField.Text.Equals("Channel") && !noTeam_Channel.ToList<string>().Any(i => i.Equals(txtNewValue.Text)))
                    {
                        MessageBox.Show("Team Name should be changed after changing Channel", Constant.SYS_INFORMATION, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        cbField.SelectedItem = "Team Name";
                        txtNewValue.Text = "New Team";
                        txtNewValue.Focus();
                    }
                    RefreshEmploymentChangeCount();


                    MessageBox.Show("Change info saved.", Constant.SYS_INFORMATION, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (txtNewValue.Text != null && saleInfoTemp != null)
                {
                    //save in datatable -> view 
                    DataRow dr = dtDataSaleInfoTemp.NewRow();
                    DataRow[] foundRows = dtDataSaleInfoTemp.Select("ProfileID= '" + saleInfoTemp.ProfileID + "' AND FieldChange = '" + cbField.Text + "'");
                    if (foundRows.Length > 0)
                    {
                        foundRows[0]["NewValue"] = txtNewValue.Text;
                    }
                    else
                    {
                        dr["ProfileID"] = saleInfoTemp.ProfileID;
                        dr["FieldChange"] = cbField.Text;
                        dr["OldValue"] = txtOldValue.Text;
                        dr["NewValue"] = txtNewValue.Text;
                        dtDataSaleInfoTemp.Rows.Add(dr);
                    }
                    if (cbField.Text.Equals("Channel") && !noTeam_Channel.ToList<string>().Any(i => i.Equals(txtNewValue.Text)))
                    {
                        var result = MessageBox.Show("Team Name should be changed after changing Channel", Constant.SYS_INFORMATION, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        if (result == System.Windows.Forms.DialogResult.OK)
                        {
                            cbField.SelectedIndex = cbField.FindStringExact("Team Name");
                            txtNewValue.Text = "Team";
                            txtNewValue.Focus();
                        }
                        return;
                    }

                    RefreshEmploymentChangeCount();

                    MessageBox.Show("Change info saved.", Constant.SYS_INFORMATION, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Nothing to change.", Constant.SYS_INFORMATION, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.InnerException == null ? ex.Message : ex.InnerException.Message, Constant.SYS_ERROR, MessageBoxButtons.OK);
                logger.Error(ex.Message + " - " + ex.StackTrace);
            }
        }

        private void dgvData_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            try
            {
                int selectedRowCount = dgvData.Rows.GetRowCount(DataGridViewElementStates.Selected);
                if (selectedRowCount > 0)
                {
                    DataRow dr = ((DataRowView)dgvData.SelectedRows[0].DataBoundItem).Row;
                    saleInfoTemp = UnPackObjectData_SaleInfo(dr);
                    LoadFieldName();
                    txtProfileIDChange.Text = saleInfoTemp.ProfileID;
                    txtBatchFileChange.Text = saleInfoTemp.BatchFileID;
                    cbField.SelectedIndex = 0;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error");
                logger.Error(ex.Message + " - " + ex.StackTrace);
            }


        }
        private void cbField_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtNewValue.Text = "";
            txtNewValue.WatermarkText = "";
            if (saleInfoTemp != null && cbField.SelectedItem != null)
            {
                string dataType = saleInfoTemp.GetType().GetProperty(((System.Collections.Generic.KeyValuePair<string, string>)(cbField.SelectedItem)).Key).PropertyType.Name;
                if (!dataType.ToUpper().Equals("STRING"))
                {
                    txtOldValue.Text = ((DateTime)saleInfoTemp.GetType().GetProperty(((System.Collections.Generic.KeyValuePair<string, string>)(cbField.SelectedItem)).Key).GetValue(saleInfoTemp, null)).ToShortDateString();
                    txtNewValue.WatermarkText = "dd/mm/yyyy";
                }
                else
                {
                    txtOldValue.Text = saleInfoTemp.GetType().GetProperty(((System.Collections.Generic.KeyValuePair<string, string>)(cbField.SelectedItem)).Key).GetValue(saleInfoTemp, null).ToString();
                }
            }
        }

        #endregion





        /// <summary>
        /// Load data form Masterdata table base on Master ID
        /// </summary>
        /// <param name="masterId">Use MasterData.MASTERID</param>
        /// <returns>Return an Array of Key value in Master datatable</returns>
        public string[] LoadMasterData(string masterId)
        {
            string masterId_original = masterId.Replace(" ", string.Empty);
            List<string> getList = new List<string>();
            new MasterDataBLL().GetById(masterId_original).Rows.OfType<DataRow>().ToList<DataRow>().ForEach(r => getList.Add(r["KeyValue"].ToString()));
            string[] array = getList.ToArray<string>();
            return array;
        }

        /// <summary>
        /// Load autocompleted value for textbox newValue
        /// </summary>
        /// <param name="source">Array of Master data</param>
        public void AutoCompleteNewValue(string[] source)
        {
            txtNewValue.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            txtNewValue.AutoCompleteSource = AutoCompleteSource.CustomSource;
            var sourceCollection = new AutoCompleteStringCollection();
            sourceCollection.AddRange(source);
            txtNewValue.AutoCompleteCustomSource = sourceCollection;
        }

        private void txtNewValue_Click(object sender, EventArgs e)
        {
            string[] autoCompletedfield = new string[] { "Channel", "Team Name", "Role", "Level", "Status" };
            if (autoCompletedfield.Contains(cbField.Text))
            {
                AutoCompleteNewValue(LoadMasterData(cbField.Text.ToUpper()));
            }
        }


        private void LoadFieldName()
        {
            cbField.DataSource = null;
            string[] bannedField = new string[] { "ID", "ProfileID", "BatchFileID" };
            var dataSource = new BindingList<KeyValuePair<string, string>>();
            if (saleInfoTemp != null)
            {

                PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(SaleInfo));

                foreach (PropertyDescriptor prop in properties)
                {
                    if (!bannedField.Contains(prop.Name))
                    {
                        //cbField.Items.Add(prop.Name);
                        if (prop.Name.Equals("PersonalCode")) //23Jan2015
                        {
                            continue;
                        }
                        dataSource.Add(new KeyValuePair<string, string>(prop.Name, SaleInfo_FieldLabelDict[prop.Name]));
                    }
                }
                cbField.DataSource = dataSource;
                cbField.ValueMember = "Key";
                cbField.DisplayMember = "Value";
            }
        }


        private void RefreshEmploymentChangeCount()
        {
            lbInfoEmployment.Text = "Number of Change(s) :" + (dtDataSaleInfoTemp != null ? dtDataSaleInfoTemp.Rows.Count.ToString() : "0");
        }

        private bool ValidateUpdateChange()
        {
            try
            {
                //Check empty field
                if (cbField.Text.Equals(""))
                {
                    MessageBox.Show("Field cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }
                if (string.IsNullOrEmpty(txtNewValue.Text.Trim()))
                {
                    MessageBox.Show("New Value cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtNewValue.Focus();
                    return false;
                }

                //Check Channel, TeamName, Role, Status, Level 
                string[] fieldbeCheckExistence = new string[] { "Channel", "TeamName", "Role", "Status", "Level" };
                if (fieldbeCheckExistence.Contains(cbField.Text))
                {
                    if (!LoadMasterData(cbField.Text).Contains<string>(txtNewValue.Text))
                    {
                        MessageBox.Show("Please input again. This value is not satisfied", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtNewValue.Focus();
                        return false;
                    }
                }

                //Check JoiningDate, PromotionTransferDate, DateOfBirth, IDIssuedDate, ContractSignDate, ContractExpiryDate
                string[] fieldbeCheckDate = new string[] { "Joining Date", "Promotion Transfer Date", "Date Of Birth", "ID Issued Date", "Contract Sign Date", "Contract Expiry Date" };
                if (fieldbeCheckDate.Contains(cbField.Text))
                {
                    Regex rgx = new Regex(@"^([0]?[1-9]|[1|2][0-9]|[3][0|1])[./-]([0]?[1-9]|[1][0-2])[./-]([0-9]{4}|[0-9]{2})$");
                    if (!rgx.IsMatch(txtNewValue.Text))
                    {
                        MessageBox.Show("Please input right date format: dd/mm/yyyy", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtNewValue.Focus();
                        return false;
                    }
                }
                return true;
            }
            catch (Exception ex) { throw ex; }
        }

        private void btnViewChange_Click(object sender, EventArgs e)
        {
            try
            {
                if (dtDataSaleInfoTemp != null && dtDataSaleInfoTemp.Rows.Count > 0)
                {
                    frmSaleDataChange frmSaleDataChange = new frmSaleDataChange(ref dtDataSaleInfoTemp);
                    DialogResult result = frmSaleDataChange.ShowDialog(this);
                    if (result == DialogResult.OK || result == DialogResult.None || result == DialogResult.Cancel)
                    {
                        dtDataSaleInfoTemp = frmSaleDataChange.dtSaleInfoChange;

                        RefreshEmploymentChangeCount();
                    }
                }
                else
                {
                    MessageBox.Show("Nothing change to view.", Constant.SYS_INFORMATION, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.InnerException == null ? ex.Message : ex.InnerException.Message, Constant.SYS_ERROR, MessageBoxButtons.OK);
                logger.Error(ex.Message + " - " + ex.StackTrace);
            }
        }

        private void btnExportChange_Click(object sender, EventArgs e)
        {
            try
            {
                if (dtDataSaleInfoTemp != null && dtDataSaleInfoTemp.Rows.Count > 0)
                {
                    //insert BatchFileChangeUpload DB
                    int IDFileBatchUpload = 0;
                    BatchFileChangeUploadBLL batchFileChangeBll = new BatchFileChangeUploadBLL();
                    string filename = "Manual_" + DateTime.Now.ToString("MMddyyyy");
                    batchFileChangeBll.Save(new BatchFileChangeUpload() { CreatedDate = MiscHelper.DateTimeToShort(DateTime.Now), FileName = filename, Status = Constant.NEED_TO_VERIFY, IsSentMail = "No" }, ref IDFileBatchUpload);

                    foreach (DataRow dr in dtDataSaleInfoTemp.Rows)
                    {
                        PackObject(dr, IDFileBatchUpload.ToString());
                    }

                    //insert Sale ChangeRequest DB
                    SaleChangeRequestBLL saleChangeRequestBll = new SaleChangeRequestBLL();
                    saleChangeRequestBll.Save(saleChangeRequestList);
                    //Refresh all field and textbox
                    dtDataSaleInfoTemp.Rows.Clear();
                    RefreshEmploymentChangeCount();
                    txtProfileIDChange.Text = "";
                    txtBatchFileChange.Text = "";
                    cbField.SelectedText = "";
                    txtOldValue.Text = "";
                    txtNewValue.Text = "";
                    MessageBox.Show(Constant.SALE_EXPORT_SUCCESS, Constant.SYS_INFORMATION, MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show(Constant.SALE_NO_CHANGE, Constant.SYS_INFORMATION, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.InnerException == null ? ex.Message : ex.InnerException.Message, Constant.SYS_ERROR, MessageBoxButtons.OK);
                logger.Error(ex.Message + " - " + ex.StackTrace);
            }
        }

        private void PackObject(DataRow drData, string batchFileChangeID)
        {
            SaleChangeRequest saleChangeRequest = new SaleChangeRequest();
            saleChangeRequest.ProfileID = drData["ProfileID"].ToString();
            saleChangeRequest.BatchFile = drData["BatchFile"].ToString();
            saleChangeRequest.FieldChange = drData["FieldChange"].ToString();
            saleChangeRequest.OldValue = drData["OldValue"].ToString();
            saleChangeRequest.NewValue = drData["NewValue"].ToString();
            saleChangeRequest.BatchFileChangeID = batchFileChangeID;
            saleChangeRequestList.Add(saleChangeRequest);
        }

        private void PackObjectSaleChangeTemp(DataRow drData, string batchFileChangeID)
        {
            SaleChangeTemp saleChangeTemp = new SaleChangeTemp();
            saleChangeTemp.ProfileID = drData["ProfileID"].ToString();
            saleChangeTemp.BatchFile = drData["BatchFile"].ToString();
            saleChangeTemp.FieldChange = drData["FieldChange"].ToString();
            saleChangeTemp.OldValue = drData["OldValue"].ToString();
            saleChangeTemp.NewValue = drData["NewValue"].ToString();
            saleChangeTempList.Add(saleChangeTemp);
        }

        private void lbInfoEmployment_MouseHover(object sender, EventArgs e)
        {
            RefreshEmploymentChangeCount();
        }

     

        private void frmSalesMgmt_FormClosing(object sender, FormClosingEventArgs e)
        {
            new SaleChangeTempBLL().ClearAll();
            foreach (DataRow row in dtDataSaleInfoTemp.Rows)
            {
                SaleChangeTemp saleChange = new SaleChangeTemp();
                saleChange.ProfileID = row["ProfileID"].ToString();
                saleChange.FieldChange = row["FieldChange"].ToString();
                saleChange.BatchFile = row["BatchFile"].ToString();
                saleChange.OldValue = row["OldValue"].ToString();
                saleChange.NewValue = row["NewValue"].ToString();
                saleChangeTempList.Add(saleChange);
            }

            new SaleChangeTempBLL().Save(saleChangeTempList);
        }
    }
}
